package com.maple.webrtc.core;


import com.blankj.utilcode.util.GsonUtils;
import com.maple.webrtc.utils.LogUtils;

import org.webrtc.DataChannel;
import org.webrtc.IceCandidate;
import org.webrtc.MediaStream;
import org.webrtc.PeerConnection;
import org.webrtc.RtpReceiver;
import org.webrtc.RtpTransceiver;

public class PeerConnectionObserverAdapter implements PeerConnection.Observer {

    private String tag;

    public PeerConnectionObserverAdapter(String tag){
        this.tag = tag + "------------->";
    }


    @Override
    public void onSignalingChange(PeerConnection.SignalingState signalingState) {
        LogUtils.logGGQ(this.tag + "onSignalingChange:" + signalingState.name());
    }

    @Override
    public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
        LogUtils.logGGQ(this.tag + "onIceConnectionChange：" + iceConnectionState.name());
    }

    @Override
    public void onIceConnectionReceivingChange(boolean receiving) {
        LogUtils.logGGQ(this.tag + "onIceConnectionReceivingChange：" + receiving);
    }

    @Override
    public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
        LogUtils.logGGQ(this.tag + "onIceGatheringChange：" + iceGatheringState.name());
    }

    @Override
    public void onIceCandidate(IceCandidate iceCandidate) {
        LogUtils.logGGQ(this.tag + "onIceCandidate:" + GsonUtils.toJson(iceCandidate));
    }

    @Override
    public void onIceCandidatesRemoved(IceCandidate[] iceCandidates) {
        for (IceCandidate iceCandidate : iceCandidates) {
            LogUtils.logGGQ(this.tag + "onIceCandidatesRemoved:" + GsonUtils.toJson(iceCandidate));
        }
    }

    @Override
    public void onAddStream(MediaStream mediaStream) {
        LogUtils.logGGQ(this.tag + "onAddStream:" + GsonUtils.toJson(mediaStream));
    }

    @Override
    public void onTrack(RtpTransceiver transceiver) {
        PeerConnection.Observer.super.onTrack(transceiver);
        LogUtils.logGGQ(this.tag + "onTrack:" + GsonUtils.toJson(transceiver));
    }

    @Override
    public void onRemoveStream(MediaStream mediaStream) {
        LogUtils.logGGQ(this.tag + "onRemoveStream:" + GsonUtils.toJson(mediaStream));
    }

    @Override
    public void onDataChannel(DataChannel dataChannel) {
        LogUtils.logGGQ(this.tag + "onDataChannel:" + GsonUtils.toJson(dataChannel));
    }

    @Override
    public void onRenegotiationNeeded() {
        LogUtils.logGGQ(this.tag + "onRenegotiationNeeded");
    }

    @Override
    public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
        LogUtils.logGGQ(this.tag + "onAddTrack:" + GsonUtils.toJson(rtpReceiver));
        for (MediaStream mediaStream : mediaStreams) {
            LogUtils.logGGQ(this.tag + "onAddTrack:" + GsonUtils.toJson(mediaStream));
        }
    }
}
